﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PinCity.Models.Repositories;

namespace PinCity.Controllers
{
    /// <summary>
    /// Controller, that is used to display test data on the screen.
    /// It is usefull to debug and monitor back-end part of the code.
    /// </summary>
    public class TestingController : Controller
    {
        /// <summary>
        /// A string, that contains data to display.
        /// </summary>
        private string _output = "";

        /// <summary>
        /// Main action of this controller, accessed by http://localhost:xxx/Tesing url.
        /// </summary>
        /// <returns>A string, that needs to be displayed on the screen.</returns>
        public string Index()
        {
            this.WriteLine("This is a testing controller, feel free to modify it as you wish.");
            this.WriteLine("Everything, passed to Write and WriteLine methods will be displayed on this page.");
            this.WriteLine("Use it to display any data during debug or development.");
            this.WriteLine("If you make changes to this class - <h3>Do not commit them.</h3>");
            this.WriteLine("And yes - you can use simple HTML.");
            return this._output;
            
        }

        public string TestDataFiller(int rolesCount, int usersCount, int stuffCount)
        {
            TestDataGenerationHelper.ULTRAFillRepositories(rolesCount, usersCount, stuffCount);
            return "OK";
        }

        /// <summary>
        /// Write text to the output. Append new line at the end.
        /// </summary>
        /// <param name="text">Text to display.</param>
        private void WriteLine(string text) 
        {
            this._output += text + "<br />";    
        }

        /// <summary>
        /// Write text to the output.
        /// </summary>
        /// <param name="text">Text to display.</param>
        private void Write(string text)
        {
            this._output += text;
        }

        /// <summary>
        /// Write string represantation of an object to the output.
        /// </summary>
        /// <param name="obj">Object to write.</param>
        private void Write(object obj)
        {
            this.Write(obj == null ? "null" : obj.ToString());
        }

        /// <summary>
        /// Write string represantation of an object to the output. Append new line at the end.
        /// </summary>
        /// <param name="obj">Object to write.</param>
        private void WriteLine(object obj)
        {
            this.WriteLine(obj == null ? "null" : obj.ToString());            
        }
    }
}
